package com.sciencep.pro.core.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dingtalk.api.response.OapiUserSimplelistResponse;
import com.sciencep.pro.common.config.Constant;
import com.sciencep.pro.common.domain.QueryRequest;
import com.sciencep.pro.core.dao.ProBaseInfoMapper;
import com.sciencep.pro.core.dao.UserWorkdailyLogMapper;
import com.sciencep.pro.core.domain.dto.dropdown.ProSelectVO;
import com.sciencep.pro.core.domain.dto.home.*;
import com.sciencep.pro.core.domain.dto.prohistory.ProHistoryTo;
import com.sciencep.pro.core.domain.entity.*;
import com.sciencep.pro.core.domain.vo.workdailylog.ProjectProgressVo;
import com.sciencep.pro.core.domain.vo.workdailylog.UserDeptNamesVo;
import com.sciencep.pro.core.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

import static com.sciencep.pro.common.utils.PageHelper.getPageFromList;

/**
 * @author libe
 */

@Service
public class HomeServiceImpl implements HomeServiceService {

    @Resource
    IProBaseInfoService proBaseInfoService;

    @Resource
    ProBaseInfoMapper proBaseInfoMapper;

    @Autowired
    IUserRoleService userRoleService;

    @Autowired
    IDeptService deptService;

    @Resource
    UserWorkdailyLogMapper userWorkdailyLogMapper;

    @Autowired
    IProPlanHoursService proPlanHoursService;

    @Autowired
    IProNodeService proNodeService;

    @Autowired
    IRoleService roleService;

    @Autowired
    IUserService userService;

    @Autowired
    IProAssignmentService proAssignmentService;

    @Autowired
    IUserDeptService userDeptService;

    @Autowired
    IProHistoryService proHistoryService;

    @Override
    public OverviewInfoVO getOverVieInfo() throws ParseException {

        List<ProBaseInfo> processingPros = proBaseInfoService.list(new LambdaQueryWrapper<ProBaseInfo>().ne(ProBaseInfo::getProStatus, Constant.ProStatus.NOT_PASS));
        Integer processingCount = 0;
        Integer finshCount = 0;
        Integer notstart = 0;
        Integer approval = 0;
        for (ProBaseInfo proBaseInfo : processingPros) {
            if (proBaseInfo.getProStatus().equals(Constant.ProStatus.FINISH)) {
                finshCount++;
            }
            if (proBaseInfo.getProStatus().equals(Constant.ProStatus.PROCESSING)) {
                processingCount++;
            }
            if (proBaseInfo.getProStatus().equals(Constant.ProStatus.NOT_START)) {
                notstart++;
            }
            if (proBaseInfo.getProStatus().equals(Constant.ProStatus.TO_AUDIT)) {
                approval++;
            }
        }
        OverviewInfoVO overviewInfoVO = new OverviewInfoVO();
        overviewInfoVO.setTotal(processingPros.size());
        overviewInfoVO.setApproval(approval);
        overviewInfoVO.setInprocess(processingCount);
        overviewInfoVO.setCompleted(finshCount);
        overviewInfoVO.setNotstarted(notstart);



        //预警数量
        int delayCount = 0;
        List<ProBaseInfo> proBaseInfoList = proBaseInfoService.list(new LambdaQueryWrapper<ProBaseInfo>().eq(ProBaseInfo::getProStatus, Constant.ProStatus.PROCESSING));


        // 优化后 (第二次优化)
        delayCount = proBaseInfoMapper.selectDelayProjects();


        // 优化后 (第一次优化)
        // for (ProBaseInfo proBaseInfo : proBaseInfoList) {
        //     String projectSchedule = proBaseInfoService.getDelayedProject(proBaseInfo).getProjectSchedule();
        //     if ("项目延期".equals(projectSchedule) || "严重延期".equals(projectSchedule)) {
        //         delayCount += 1;
        //     }
        // }
        /*// 优化前
        // 原版本
        for (ProBaseInfo proBaseInfo : proBaseInfoList) {
            if (proBaseInfoService.getDelayedProject(proBaseInfo).getProjectSchedule().equals("项目延期") || proBaseInfoService.getDelayedProject(proBaseInfo).getProjectSchedule().equals("严重延期")) {
                delayCount += 1;
            }
        }*/
        overviewInfoVO.setDelayed(delayCount);

        return overviewInfoVO;
    }

    @Override
    public List<ParticipatedInInfoVO> getParticipatedInInfoVO(String userId) {
        List<ParticipatedInInfoVO> result;
        Set<String> roleNameSet = roleService.getRoleByUserId(userId).stream()
                .map(Role::getRoleName).collect(Collectors.toSet());

        // 优化 （2021-3-29）
        List<ProjectProgressVo> projectProgressVos = proBaseInfoMapper.selectProjectProgress();

        if (roleNameSet.contains("公司领导") || roleNameSet.contains("财务人员")) {
            //获取所有项目
            result = proBaseInfoMapper.getParticipatedInInfoVO(userId, null, 1);

            // 优化 （2021-3-29）
            result.forEach(e->{
                projectProgressVos.forEach(m->{
                    if (e.getProId().equals(m.getId().toString())){
                        e.setProgress(m.getProgress());
                    }
                });
            });

            getCount(result);
            return result;
        }
        result = proBaseInfoMapper.getParticipatedInInfoVO(userId, null, 2);

        result.forEach(e->{
            projectProgressVos.forEach(m->{
                if (e.getProId().equals(m.getId().toString())){
                    e.setProgress(m.getProgress());
                }
            });
        });

        //20210125 新需求 有BUG  已被优化
        // result.forEach(e->{
        //     if(CollUtil.isNotEmpty(proHistoryService.list(new LambdaQueryWrapper<ProHistory>().eq(ProHistory::getProCode,e.getProCode()).eq(ProHistory::getIsDel,Constant.IsDelete.NO)))){
        //         ProHistoryTo to = proHistoryService.countProgress(e.getProCode());
        //         if(null != to){
        //             e.setProgress(to.getProgress());
        //         }
        //     }
        // });

       getCount(result);
        return result;
    }

    private void getCount(List<ParticipatedInInfoVO> result) {
        if (CollUtil.isEmpty(result)) {
            return;
        }
        for (ParticipatedInInfoVO participatedInInfoVO : result) {

            if (participatedInInfoVO.getPndCount() == null) {
                participatedInInfoVO.setPaCount(0);
            }
            if (participatedInInfoVO.getPaCount() == null) {
                participatedInInfoVO.setPaCount(0);
            }

            if (participatedInInfoVO.getPaCount() != null && participatedInInfoVO.getPndCount() != null) {
                participatedInInfoVO.setAssignFlag(participatedInInfoVO.getPndCount() > participatedInInfoVO.getPaCount() || participatedInInfoVO.getPndCount() == 0);
            }

        }

    }


    @Override
    public List<ManPowerExpendByProjectVO> getManPowerExpendByProjectVOList(Set<String> proNos) {

        List<ManPowerExpendByProjectVO> result = proBaseInfoMapper.getManPowerExpendByProjectVOList(proNos);
        //20210125 新需求
        List<ManPowerExpendByProjectVO> roleVoList = proHistoryService.getVoList(proNos);
        List<ManPowerExpendByProjectVO> newManpowerExpendByRoleVOList = new ArrayList<>();

        Iterator<ManPowerExpendByProjectVO> it = roleVoList.iterator();
        while (it.hasNext()){
            boolean flag = true;
            ManPowerExpendByProjectVO r = it.next();
            for(ManPowerExpendByProjectVO m :result) {
                if (m.getText().equals(r.getText())) {
                    m.setValue(new BigDecimal(m.getValue()).add(new BigDecimal(null == r.getValue() ? "0" : r.getValue())).toString());
                    it.remove();
                    flag = false;
                    break;
                }
            }
            if(flag) {
                ManPowerExpendByProjectVO manpowerExpendByRoleVO = new ManPowerExpendByProjectVO();
                manpowerExpendByRoleVO.setText(r.getText());
                manpowerExpendByRoleVO.setValue(r.getValue());
                newManpowerExpendByRoleVOList.add(manpowerExpendByRoleVO);
            }
        }
        result.addAll(newManpowerExpendByRoleVOList);
        return result;
    }

    @Override
    public List<ManpowerExpendByRoleVO> getManpowerExpendByRoleVOList(Set<String> proNos) {
        List<ManpowerExpendByRoleVO> manpowerExpendByRoleVOList = proBaseInfoMapper.getManpowerExpendByRoleVOList(proNos);
        if (null != proBaseInfoMapper.getManpowerExpendByOTHER().getValue()) {
            manpowerExpendByRoleVOList.add(proBaseInfoMapper.getManpowerExpendByOTHER());
        }

        //20210125 新需求
        List<ManpowerExpendByRoleVO> roleVoList = proHistoryService.getRoleVoList(proNos);
        List<ManpowerExpendByRoleVO> newManpowerExpendByRoleVOList = new ArrayList<>();

        Iterator<ManpowerExpendByRoleVO> it = roleVoList.iterator();
        while (it.hasNext()){
            boolean flag = true;
            ManpowerExpendByRoleVO r = it.next();
            for(ManpowerExpendByRoleVO m :manpowerExpendByRoleVOList) {
                if (m.getText().equals(r.getText())) {
                    m.setValue(new BigDecimal(m.getValue()).add(new BigDecimal(r.getValue())).toString());
                    it.remove();
                    flag = false;
                    break;
                }
            }
            if(flag) {
                ManpowerExpendByRoleVO manpowerExpendByRoleVO = new ManpowerExpendByRoleVO();
                manpowerExpendByRoleVO.setText(r.getText());
                manpowerExpendByRoleVO.setValue(r.getValue());
                newManpowerExpendByRoleVOList.add(manpowerExpendByRoleVO);
            }
        }
        manpowerExpendByRoleVOList.addAll(newManpowerExpendByRoleVOList);
        List<ManpowerExpendByRoleVO> tempList = manpowerExpendByRoleVOList.stream().filter(e->e.getValue() != null).collect(Collectors.toList());
        Map<String,List<ManpowerExpendByRoleVO>> retMap = tempList.stream().collect(Collectors.groupingBy(ManpowerExpendByRoleVO::getText));
        List<ManpowerExpendByRoleVO> retList = new ArrayList<>();
        for(Map.Entry<String,List<ManpowerExpendByRoleVO>> map : retMap.entrySet()){
            ManpowerExpendByRoleVO vo = new ManpowerExpendByRoleVO();
            vo.setText(map.getKey());
            Double value = 0d;
            for(ManpowerExpendByRoleVO tvo : map.getValue()){
                value +=Double.valueOf(tvo.getValue());
            }
            vo.setValue(String.format("%.2f",value));
            retList.add(vo);
        }
        return retList;
    }

    @Override
    public List<DailyReportReivewVO> getDailyReportReivewVOList(String userId) {


        List<DailyReportReivewVO> result = new ArrayList<>();
        // 项目表probaseinfo中查找项目负责人ID为当前登录人的所有项目
        //result.addAll(userWorkdailyLogMapper.getToAuditLogByProManager(userId));

        List<ProAssignment> proAssignmentList = proAssignmentService.list(new LambdaQueryWrapper<ProAssignment>().
                groupBy(ProAssignment::getProId,ProAssignment::getUserId).
                eq(ProAssignment::getReviewId, userId));
        Set<Long> reviewIds = proAssignmentList.stream().map(ProAssignment::getProId).collect(Collectors.toSet());
        Set<String> proUserIdSet = proAssignmentList.stream().map(ProAssignment::getUserId).collect(Collectors.toSet());
        List<String> proNos = new ArrayList<>();
        reviewIds.forEach(e->{
            proNos.add(proBaseInfoService.getOne(new LambdaQueryWrapper<ProBaseInfo>().eq(ProBaseInfo::getId,e)).getProCode());
        });

        if(CollUtil.isNotEmpty(proUserIdSet)) {
            result.addAll(userWorkdailyLogMapper.getReviewList(proUserIdSet,proNos));
        }

        Set<String> deptSet = deptService.
                list(new LambdaQueryWrapper<Dept>().like(Dept::getDeptManagerUseridList, userId))
                .stream().map(Dept::getDeptId).collect(Collectors.toSet());
        if (CollUtil.isNotEmpty(deptSet)) {

            //递归查询部门下所有部门
            Set<String> allFollowDeptSet = new HashSet<>();
            if(!CollectionUtils.isEmpty(deptSet)){
                allFollowDeptSet.addAll(deptSet);
                for(String tempdDept : deptSet){
                    queryfollowdeptSet(allFollowDeptSet,tempdDept);
                }
            }
//            List<Dept> depts = deptService.list();
//            //查询所有子部门
//            deptSet = ProBaseInfoServiceImpl.getSubDeptList(deptSet, depts);

            //找到项目主管下的所有人
            Set<String> userSet = new HashSet<>();
            allFollowDeptSet.forEach(e -> {
                userDeptService.list(new LambdaQueryWrapper<UserDept>().eq(UserDept::getDeptId,e)).forEach(d->{
                    userSet.add(d.getUserId());
                });
            });

            result.addAll(userWorkdailyLogMapper.getToAuditLogByDeptManager(allFollowDeptSet,userSet));
        }

        List<DailyReportReivewVO> list= result.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()
                -> new TreeSet<>(Comparator.comparing(DailyReportReivewVO::getReportId))), ArrayList::new));
        list.sort(Comparator.comparing(DailyReportReivewVO::getSubmitTime).reversed());
        return list;

    }

    private void queryfollowdeptSet(Set<String> deptSet, String tempdDept) {
        Set<String> tempSet = deptService.list(new LambdaQueryWrapper<Dept>().like(Dept::getParentId, tempdDept))
                .stream().map(Dept::getDeptId).collect(Collectors.toSet());
        if(!CollectionUtils.isEmpty(tempSet)){
            for(String temp : tempSet){
                deptSet.add(temp);
                queryfollowdeptSet(deptSet,temp);
            }
        }
        return;
    }

    @Override
    public List<NewyAssignedVO> getNewyAssignedVO(String userId) {
        //项目流转人
        List<ProBaseInfo> proBaseInfoList = proBaseInfoService.list(new QueryWrapper<ProBaseInfo>().eq("proManager", userId).eq("proStatus", "6").orderByDesc("createDate"));
        for (ProBaseInfo proBaseInfo : proBaseInfoList) {
            proBaseInfo.setIsProManager(true);
        }
        //项目被分配的人
        List<ProAssignment> proAssignmentList = proAssignmentService.list(new LambdaQueryWrapper<ProAssignment>().eq(ProAssignment::getUserId, userId).apply(" (readType != 1 OR readType IS NULL)").orderByDesc(ProAssignment::getCreateDate))
                .stream()
                .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(ProAssignment::getProId))), ArrayList::new));
        List<ProBaseInfo> proBaseInfoList1 = new ArrayList<>();
        for (ProAssignment proAssignment : proAssignmentList) {
            ProBaseInfo proBaseInfo = proBaseInfoService.getOne(new LambdaQueryWrapper<ProBaseInfo>().eq(ProBaseInfo::getId, proAssignment.getProId()).eq(ProBaseInfo::getProStatus, Constant.ProStatus.PROCESSING));
            if (null != proBaseInfo) {
                proBaseInfoList1.add(proBaseInfo);
            }
        }

        proBaseInfoList.addAll(proBaseInfoList1);
        List<NewyAssignedVO> result = new ArrayList<>();
        Map<Long, String> nodeMap = proNodeService.list().stream().collect(Collectors.toMap(ProNode::getId, ProNode::getNodeName));
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        if (CollUtil.isNotEmpty(proBaseInfoList)) {
            for (ProBaseInfo proBaseInfo : proBaseInfoList) {
                NewyAssignedVO newyAssignedVO = new NewyAssignedVO();
                newyAssignedVO.setProId(proBaseInfo.getId() + "");
                newyAssignedVO.setProName(proBaseInfo.getProName());
                newyAssignedVO.setProCode(proBaseInfo.getProCode());
                newyAssignedVO.setIsProManager(proBaseInfo.getIsProManager());
                newyAssignedVO.setDeptName(deptService.getOne(new LambdaQueryWrapper<Dept>().eq(Dept::getDeptId, proBaseInfo.getDeptId())).getDeptName());
                if (proBaseInfo.getProStartDay() != null && proBaseInfo.getProEndday() != null) {
                    newyAssignedVO.setPeriod(formatter.format(proBaseInfo.getProStartDay()) + "~" + formatter.format(proBaseInfo.getProEndday()));
                }
                newyAssignedVO.setProNode(nodeMap.get(Long.valueOf(proBaseInfo.getProNodeId())));
                newyAssignedVO.setProPriorityStr(proBaseInfo.getProPriority() + "");
                //指派周期和计划投入人天
                List<ProAssignment> proAssignments = proAssignmentService.list(new LambdaQueryWrapper<ProAssignment>().eq(ProAssignment::getProId, proBaseInfo.getId()).eq(ProAssignment::getUserId, userId));
                StringBuilder assignedPeriod = new StringBuilder();
                Float proPlan = 0F;
                if (CollUtil.isNotEmpty(proAssignments)) {
                    int i = 0;
                    for (ProAssignment proAssignment : proAssignments) {
                        if (i > 0) {
                            assignedPeriod.append(";" + formatter.format(proAssignment.getInputStart()) + "~" + formatter.format(proAssignment.getInputEnd()));
                        } else {
                            assignedPeriod.append(formatter.format(proAssignment.getInputStart()) + "~" + formatter.format(proAssignment.getInputEnd()));
                        }
                        proPlan += proAssignment.getInputHours() == null ? 0 : proAssignment.getInputHours();
                        i++;
                    }
                }
                newyAssignedVO.setAssignedPeriod(assignedPeriod.toString());
                newyAssignedVO.setTotalPutin(proPlan.toString());
                result.add(newyAssignedVO);
            }
            return result;
        }

        return new ArrayList<>();
    }

    @Override
    public Page<ManpowerUtilizationVO> getManpowerUtilizationVO(QueryRequest queryRequest) {
        List<ManpowerUtilizationVO> manpowerUtilizationVOList = new ArrayList<>();
        List<ManpowerUtilizationVO> workPlan = proBaseInfoMapper.getWorkPlan();//本月计划人天
        List<ManpowerUtilizationVO> workPutin = proBaseInfoMapper.getWorkPutin();//本月打卡人天
        if (CollUtil.isNotEmpty(workPlan)) {

            Calendar calendarBegin = Calendar.getInstance();
            calendarBegin.set(Calendar.DAY_OF_MONTH, 1);//设置为1号,当前日期既为本月第一天
            Calendar calendarEnd = Calendar.getInstance();
            calendarEnd.set(Calendar.DAY_OF_MONTH, calendarEnd.getActualMaximum(Calendar.DAY_OF_MONTH));//获取当前月最后一天
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            List<Map<String, Boolean>> workDay = null;
            try {
                workDay = proBaseInfoService.getWorkDay(sdf.format(calendarBegin.getTime()), sdf.format(calendarEnd.getTime()));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            int wordDays = 0;
            for (Map<String, Boolean> e : workDay) {
                for (Map.Entry<String, Boolean> vo : e.entrySet()) {
                    if (vo.getValue().equals(true)) {
                        wordDays += 1;
                    }
                }
            }

            //  =========================   2021-03-29 优化代码   ==================  开始
            List<UserDeptNamesVo> userDeptNames = proBaseInfoMapper.getUserDeptNames();
            //  =========================   2021-03-29 优化代码   ==================  结束

            for (ManpowerUtilizationVO manpowerUtilizationVO : workPlan) {   // size = 44


                //  =========================   2021-03-29 优化代码   ================== 开始
                String deptName = null;
                if(CollectionUtil.isNotEmpty(userDeptNames)){
                    for (UserDeptNamesVo userDeptName : userDeptNames) {
                        if (manpowerUtilizationVO.getUserId().equals(userDeptName.getUserId())){
                            deptName = userDeptName.getDeptNames();
                        }
                    }
                }
                manpowerUtilizationVO.setDeptName(deptName);
                //  =========================   2021-03-29 优化代码   ================== 结束

                if (manpowerUtilizationVO.getWorkPlan().equals("0.0")) {
                    manpowerUtilizationVO.setWorkPlan("0.00");
                } else {
                    DecimalFormat df = new DecimalFormat("#.00");
                    String number = df.format(Double.valueOf(manpowerUtilizationVO.getWorkPlan()));
                    manpowerUtilizationVO.setWorkPlan(number);
                }
                // manpowerUtilizationVO.setDeptName(proBaseInfoMapper.getDept(manpowerUtilizationVO.getUserId()));
                manpowerUtilizationVO.setUserName(manpowerUtilizationVO.getUserName());
                manpowerUtilizationVO.setPosition(manpowerUtilizationVO.getPosition());
                manpowerUtilizationVO.setEmployeeType(manpowerUtilizationVO.getEmployeeType());
                manpowerUtilizationVO.setEmployeeStatus(manpowerUtilizationVO.getEmployeeStatus());

                manpowerUtilizationVO.setWorkDate(String.valueOf(wordDays));
                if (CollUtil.isNotEmpty(workPutin)) {
                    for (ManpowerUtilizationVO manpowerUtilization : workPutin) {
                        if (manpowerUtilizationVO.getUserId().equals(manpowerUtilization.getUserId()) && null != manpowerUtilization.getWorkPutin()) {
                            manpowerUtilizationVO.setWorkPutin(manpowerUtilization.getWorkPutin());
                        }
                    }
                }
                if (null != manpowerUtilizationVO.getWorkPlan()) {
                    manpowerUtilizationVO.setWorkPlan(manpowerUtilizationVO.getWorkPlan());
                    String zero = "0.00%";
                    if (null != manpowerUtilizationVO.getWorkPutin()) {
                        //getWorkPlan计划等于0,getWorkPutin实际大于0,稼动率100;计划等于0,实际等于0,稼动率0;计划大于0,实际等于0,稼动率0
                        if (manpowerUtilizationVO.getWorkPlan().equals("0.00")) {
                            if (manpowerUtilizationVO.getWorkPutin().equals("0.00")) {
                                manpowerUtilizationVO.setUtilization(zero);
                            } else {
                                manpowerUtilizationVO.setUtilization("100%");
                            }
                        } else {
                            if (manpowerUtilizationVO.getWorkPutin().equals("0.00")) {
                                manpowerUtilizationVO.setUtilization(zero);
                            } else {
                                DecimalFormat df = new DecimalFormat("###.0000");
                                String number = df.format(Double.valueOf(manpowerUtilizationVO.getWorkPutin()) / Double.valueOf(manpowerUtilizationVO.getWorkPlan()));
                                //DecimalFormat df1 = new DecimalFormat("###.00");
                                manpowerUtilizationVO.setUtilization(number.equals(".0000") ? "0.00%" : String.format("%.2f",Double.valueOf(number) * 100) + "%");
                            }
                        }
                    } else {
                        manpowerUtilizationVO.setWorkPutin("0.00");
                        manpowerUtilizationVO.setUtilization(zero);
                    }
                }
                manpowerUtilizationVOList.add(manpowerUtilizationVO);
            }
        }
        return getPageFromList(manpowerUtilizationVOList, queryRequest.getPageNum(), queryRequest.getPageSize());
    }

    @Override
    public List<MyPowerExpendVO> getMyPowerExpandVO(String userId) {

        List<MyPowerExpendVO> result = new ArrayList<>();
        result.addAll(userWorkdailyLogMapper.getMyPowerExpandVO(userId));

        return result;
    }

    @Override
    public List<MyMandyProgressVO> getMyMandyProgressVO(String userId) {


        List<MyMandyProgressVO> result = new ArrayList<>();
        result.addAll(userWorkdailyLogMapper.getMyMandyProgressVO(userId));
        for (MyMandyProgressVO myMandyProgressVO : result) {
            if (null != myMandyProgressVO.getPutinPlan() && myMandyProgressVO.getPutinPlan().compareTo(BigDecimal.ZERO) != 0) {
                if (myMandyProgressVO.getPutinDone().divide(myMandyProgressVO.getPutinPlan(), 2, RoundingMode.HALF_UP).compareTo(new BigDecimal("1")) >= 1) {
                    myMandyProgressVO.setProgress(new BigDecimal("100"));
                } else {
                    myMandyProgressVO.setProgress(myMandyProgressVO.getPutinDone().divide(myMandyProgressVO.getPutinPlan(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
                }
            } else {
                myMandyProgressVO.setProgress(new BigDecimal("0"));
            }
        }

        return result;
    }

    @Override
    public YesterdayReviewVO getYesterdayReviewVOList(String userId) {

        YesterdayReviewVO result = new YesterdayReviewVO();

        Integer sum = userService.count(new LambdaQueryWrapper<User>().eq(User::getIsDel, Constant.IsDelete.NO)
                .eq(User::getIsResign, 1));
        result.setTotal(sum).setReviewSuccess(sum).setReviewException(0);

        return result;
    }

    @Override
    public TodayReportSubmitTO getToday() {


        TodayReportSubmitTO result = new TodayReportSubmitTO();
        String date = LocalDate.now().toString();
        result.setTotal(userService.count(new LambdaQueryWrapper<User>().eq(User::getIsDel, Constant.IsDelete.NO)
                .eq(User::getIsResign, 1)));
        result.setSubmit(userWorkdailyLogMapper.getSubmit(date));
        result.setNotSubmit(result.getTotal() - result.getSubmit());


        return result;
    }


}
